﻿/*-------------------------------------------------------------------------
* 命名空间: WaferSelectV3.Models/CrystalLevelCountModel
* 类       名: CrystalLevelCountModel
* 功      能:  TD
* 时      间:  2024-05-07 9:59:20
* 版      本:  V1.0
* 作      者:  Fioman
* 格      言:  Talk is cheap,show me the code ^_^
*-------------------------------------------------------------------------*/
using Prism.Mvvm;
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Documents;
using WaferSelectV3.Common;

namespace WaferSelectV3.Models
{
    public class CrystalLevelCountModel : BindableBase
    {
        // 统计的总个数
        private static int _totalCount = 0;
        private int _levelIndex;
        private string? _detectedType;
        private int _detectedCount;
        private string? _detectedCountInfo;


        /// <summary>
        /// 统计计数对应的Index的下标,这个下标是和Level挂钩的
        /// </summary>
        public int LevelIndex
        {
            get { return _levelIndex; }
            set
            {
                _levelIndex = value;
                RaisePropertyChanged();
            }
        }

        /// <summary>
        /// 统计晶棒信息的检测类型
        /// </summary>
        public string? DetectedType
        {
            get { return _detectedType; }
            set
            {
                _detectedType = value;
                RaisePropertyChanged();
            }
        }



        /// <summary>
        /// 统计的晶棒的类别的个数
        /// </summary>
        public int DetectedCount
        {
            get { return _detectedCount; }
            set
            {
                _detectedCount = value;
                RaisePropertyChanged();
                if (LevelIndex == 38)
                {
                    _totalCount = value;
                }
                double percent;
                if (_totalCount != 0)
                {
                    percent = (double)value / _totalCount * 100;
                }
                else
                {
                    percent = 0.0;
                }
                DetectedCountInfo = $"{DetectedCount} ({percent.ToString("f2")}%)";
            }
        }


        /// <summary>
        /// 界面上显示的统计信息,带上百分号,通过上面的DetectedCount进行计算,使用Converter是不是更好一些呢
        /// </summary>
        public string? DetectedCountInfo
        {
            get { return _detectedCountInfo; }
            set
            {
                _detectedCountInfo = value;
                RaisePropertyChanged();
            }
        }

    }
}
